﻿using System;
using System.Collections.Generic;
using System.Text;
using DataProvider;
using System.Data;
using System.Data.SqlClient;

namespace BusinessLayer
{
    public class CTPXuat :XL_Bang
    {
        #region thuoc tinh
        private string _soPX;

        public string SoPX
        {
            get { return _soPX; }
            set { _soPX = value; }
        }
        private string _maVTU;

        public string MaVTU
        {
            get { return _maVTU; }
            set { _maVTU = value; }
        }
        private string _soLuong;

        public string Soluong
        {
            get { return _soLuong; }
            set { _soLuong = value; }
        }
        private string _dgXuat;

        public string DGXuat
        {
            get { return _dgXuat; }
            set { _dgXuat = value; }
        }

        #endregion

        #region cac phuong thuc
        public DataTable GetData()
        {
            StrSQL = "select * from CTPXuat";
            return GetDataTable();
        }
        public DataTable GetData(string soPX)
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "LOAD_CTPXUAT_BY_SOPX";
                command.Parameters.AddWithValue("@SOPX", soPX);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable table = new DataTable();
                adapter.Fill(table);
                close();
                return table;
            }
            catch (Exception)
            {
                close();
                return null;
            }
        }
        public bool AddNew()
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "INSERT_UPDATE_DELETE_CTPXUAT";
                command.Parameters.AddWithValue("@SOPX", _soPX);
                command.Parameters.AddWithValue("@MAVTU", _maVTU);
                command.Parameters.AddWithValue("@SLXUAT", _soLuong);
                command.Parameters.AddWithValue("@DGXUAT", _dgXuat);
                command.Parameters.AddWithValue("@TYPE", 0);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                close();
                return true;
            }
            catch (Exception)
            {
                close();
                return false;
            }
        }
        public bool Edit()
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "INSERT_UPDATE_DELETE_CTXUAT";
                command.Parameters.AddWithValue("@SOPX", _soPX);
                command.Parameters.AddWithValue("@MAVTU", _maVTU);
                command.Parameters.AddWithValue("@SLXUAT", _soLuong);
                command.Parameters.AddWithValue("@DGXUAT", _dgXuat);
                command.Parameters.AddWithValue("@TYPE", 1);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                close();
                return true;
            }
            catch (Exception)
            {
                close();
                return false;
            }
        }
        public bool Delete()
        {
            try
            {
                open();
                command = new System.Data.SqlClient.SqlCommand();
                command.CommandText = "INSERT_UPDATE_DELETE_CTPXUAT";
                command.Parameters.AddWithValue("@SOPX", _soPX);
                command.Parameters.AddWithValue("@MAVTU", _maVTU);
                command.Parameters.AddWithValue("@SLXUAT", string.Empty);
                command.Parameters.AddWithValue("@DGXUAT", string.Empty);
                command.Parameters.AddWithValue("@TYPE", 2);
                command.Connection = connect;
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                close();
                return true;
            }
            catch (Exception)
            {
                close();
                return false;
            }
        }
        #endregion
    }
}
